package com.ecar.core.order.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

public class Order implements Serializable {
	
	public static final int TYPE_BOOKING = 1;    // 订票订单
	public static final int TYPE_RENT = 2;		// 城际约租订单
	public static final int TYPE_BUS = 3;			// 跨城巴士
	public static final int TYPE_EXPRESS = 4;		// 小件快运
	public static final int TYPE_TRAVEL = 5;			// 旅游度假
	public static final int TYPE_RECEIVEORSEND=6;    //接送机
	public static final int TYPE_FAST=7;          //快车
	
	public enum ST {
		CREATED(1, "待支付"), PAID(2, "已支付"), TIMEOUT(3, "订单超时"),
		REFUNDING(4, "退款中"), REFUNDED(5, "退款完成"), FAILURE(6, "退款失败");

		private int value;
		private String txt;
		ST(int value, String txt) {
			this.value = value;
			this.txt = txt;
		}
		public int val() { return this.value; }
		public String txt() { return this.txt; }
	}
	public void to(ST st) { this.orderStatus = st.val(); }
	public boolean eq(ST ST) {
		return this.orderStatus == ST.val();
	}
	public boolean in(ST... sts) {
		for (ST ST : sts) if (eq(ST)) return true;
		return false;
	}
	
	private Date planTime;
	
	private String customerName;
	
	private String customerPhone;
	
	private Integer carType;
	
    private String id;

    private String orderNum;

    private String flightId;

    private Integer useSeats;

    private Integer wait;
    
	private Date startTime;
    
    private Date receiveTime;

    private String startAddress;

    private String startLocation;

    private String desAddress;

    private String desLocation;

    private Integer passengerId;

    private String driverId;

    private Double orderPrice;

    private Integer orderType;

    private Integer orderStatus;

    private Integer payStatus;

    private String passengerPhone;

    private String vehicleId;

    private Date createTime;
    
    private Date endTime;
    
    private String prepayId;
    
    private String parentOrder;
    
    private double actualPrice;
    
    private double deductionPrice;
    
    private String couponId;
    
    private Integer pcType;
    
    private Integer isDriver;
    
    public Integer getPcType() {
		return pcType;
	}
	public void setPcType(Integer pcType) {
		this.pcType = pcType;
	}
	public double getActualPrice() {
		return actualPrice;
	}
	public void setActualPrice(double actualPrice) {
		this.actualPrice = actualPrice;
	}
	public double getDeductionPrice() {
		return deductionPrice;
	}
	public void setDeductionPrice(double deductionPrice) {
		this.deductionPrice = deductionPrice;
	}
	public String getCouponId() {
		return couponId;
	}
	public void setCouponId(String couponId) {
		this.couponId = couponId;
	}
	public String getParentOrder() {
		return parentOrder;
	}
	public void setParentOrder(String parentOrder) {
		this.parentOrder = parentOrder;
	}
	public Date getPlanTime() {
		return planTime;
	}
	public void setPlanTime(Date planTime) {
		this.planTime = planTime;
	}
	public String getCustomerName() {
		return customerName;
	}
	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}
	public String getCustomerPhone() {
		return customerPhone;
	}
	public void setCustomerPhone(String customerPhone) {
		this.customerPhone = customerPhone;
	}
	public Integer getCarType() {
		return carType;
	}
	public void setCarType(Integer carType) {
		this.carType = carType;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public String getPrepayId() {
		return prepayId;
	}
	public void setPrepayId(String prepayId) {
		this.prepayId = prepayId;
	}

	private static final long serialVersionUID = 1L;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(String orderNum) {
        this.orderNum = orderNum;
    }

    public String getFlightId() {
        return flightId;
    }

    public void setFlightId(String flightId) {
        this.flightId = flightId;
    }

    public Integer getUseSeats() {
        return useSeats;
    }

    public void setUseSeats(Integer useSeats) {
        this.useSeats = useSeats;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getReceiveTime() {
		return receiveTime;
	}

	public void setReceiveTime(Date receiveTime) {
		this.receiveTime = receiveTime;
	}
    
    public String getStartAddress() {
        return startAddress;
    }

    public void setStartAddress(String startAddress) {
        this.startAddress = startAddress;
    }

    public String getStartLocation() {
        return startLocation;
    }

    public void setStartLocation(String startLocation) {
        this.startLocation = startLocation;
    }

    public String getDesAddress() {
        return desAddress;
    }

    public void setDesAddress(String desAddress) {
        this.desAddress = desAddress;
    }

    public String getDesLocation() {
        return desLocation;
    }

    public void setDesLocation(String desLocation) {
        this.desLocation = desLocation;
    }

    public Integer getPassengerId() {
        return passengerId;
    }

    public void setPassengerId(Integer passengerId) {
        this.passengerId = passengerId;
    }

    public String getDriverId() {
        return driverId;
    }

    public void setDriverId(String driverId) {
        this.driverId = driverId;
    }

    public Double getOrderPrice() {
        return orderPrice;
    }

    public void setOrderPrice(Double orderPrice) {
        this.orderPrice = orderPrice;
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    public Integer getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(Integer payStatus) {
        this.payStatus = payStatus;
    }

    public String getPassengerPhone() {
        return passengerPhone;
    }

    public void setPassengerPhone(String passengerPhone) {
        this.passengerPhone = passengerPhone;
    }

    public String getVehicleId() {
        return vehicleId;
    }

    public void setVehicleId(String vehicleId) {
        this.vehicleId = vehicleId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Order other = (Order) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getOrderNum() == null ? other.getOrderNum() == null : this.getOrderNum().equals(other.getOrderNum()))
            && (this.getFlightId() == null ? other.getFlightId() == null : this.getFlightId().equals(other.getFlightId()))
            && (this.getUseSeats() == null ? other.getUseSeats() == null : this.getUseSeats().equals(other.getUseSeats()))
            && (this.getStartTime() == null ? other.getStartTime() == null : this.getStartTime().equals(other.getStartTime()))
            && (this.getStartAddress() == null ? other.getStartAddress() == null : this.getStartAddress().equals(other.getStartAddress()))
            && (this.getStartLocation() == null ? other.getStartLocation() == null : this.getStartLocation().equals(other.getStartLocation()))
            && (this.getDesAddress() == null ? other.getDesAddress() == null : this.getDesAddress().equals(other.getDesAddress()))
            && (this.getDesLocation() == null ? other.getDesLocation() == null : this.getDesLocation().equals(other.getDesLocation()))
            && (this.getPassengerId() == null ? other.getPassengerId() == null : this.getPassengerId().equals(other.getPassengerId()))
            && (this.getDriverId() == null ? other.getDriverId() == null : this.getDriverId().equals(other.getDriverId()))
            && (this.getOrderPrice() == null ? other.getOrderPrice() == null : this.getOrderPrice().equals(other.getOrderPrice()))
            && (this.getOrderType() == null ? other.getOrderType() == null : this.getOrderType().equals(other.getOrderType()))
            && (this.getOrderStatus() == null ? other.getOrderStatus() == null : this.getOrderStatus().equals(other.getOrderStatus()))
            && (this.getPayStatus() == null ? other.getPayStatus() == null : this.getPayStatus().equals(other.getPayStatus()))
            && (this.getPassengerPhone() == null ? other.getPassengerPhone() == null : this.getPassengerPhone().equals(other.getPassengerPhone()))
            && (this.getVehicleId() == null ? other.getVehicleId() == null : this.getVehicleId().equals(other.getVehicleId()))
            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getOrderNum() == null) ? 0 : getOrderNum().hashCode());
        result = prime * result + ((getFlightId() == null) ? 0 : getFlightId().hashCode());
        result = prime * result + ((getUseSeats() == null) ? 0 : getUseSeats().hashCode());
        result = prime * result + ((getStartTime() == null) ? 0 : getStartTime().hashCode());
        result = prime * result + ((getStartAddress() == null) ? 0 : getStartAddress().hashCode());
        result = prime * result + ((getStartLocation() == null) ? 0 : getStartLocation().hashCode());
        result = prime * result + ((getDesAddress() == null) ? 0 : getDesAddress().hashCode());
        result = prime * result + ((getDesLocation() == null) ? 0 : getDesLocation().hashCode());
        result = prime * result + ((getPassengerId() == null) ? 0 : getPassengerId().hashCode());
        result = prime * result + ((getDriverId() == null) ? 0 : getDriverId().hashCode());
        result = prime * result + ((getOrderPrice() == null) ? 0 : getOrderPrice().hashCode());
        result = prime * result + ((getOrderType() == null) ? 0 : getOrderType().hashCode());
        result = prime * result + ((getOrderStatus() == null) ? 0 : getOrderStatus().hashCode());
        result = prime * result + ((getPayStatus() == null) ? 0 : getPayStatus().hashCode());
        result = prime * result + ((getPassengerPhone() == null) ? 0 : getPassengerPhone().hashCode());
        result = prime * result + ((getVehicleId() == null) ? 0 : getVehicleId().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        return result;
    }
    public boolean isTimeout(int timeoutInMinute) {
		return calcRemaining(timeoutInMinute) <= 0;
	}
    public int calcRemaining(int timeoutInMinute) {
		BigDecimal remaining =
			BigDecimal.valueOf(timeoutInMinute * 60)
					  .subtract(BigDecimal.valueOf(new Date().getTime())
										  .subtract(BigDecimal.valueOf(this.createTime.getTime()))
										  .abs()
										  .divide(BigDecimal.valueOf(1000), 0));
		int remainin = remaining.intValue() > 0 ? remaining.intValue() : 0;
		return remainin;
	}
	public Integer getWait() {
		return wait;
	}
	public void setWait(Integer wait) {
		this.wait = wait;
	}
	public Integer getIsDriver() {
		return isDriver;
	}
	public void setIsDriver(Integer isDriver) {
		this.isDriver = isDriver;
	}
}